#include "Enemy.h"
#include <math.h>

using namespace std;
using namespace sf;
Enemy::Enemy(Vector2f position, float health, Vector2f size, SpriteEnum spriteTexture, SpriteEnum bulletSprite) :
Character(position, health, size, spriteTexture, bulletSprite)
{
	_sprite.setFillColor(Color::Red);	
	
}


void Enemy::shoot()
{
	
	
	for (int i = 0; i != isShootingVector.size(); i++)
	{
	
		
		if (isShootingVector[i] == true)
		{
		
			bulletManager.getBulletMap()[i + 1]->setIsShooting(true);		

			if (bulletManager.getBulletMap()[i + 1]->getIsShooting())
			{

				bulletManager.getBulletMap()[i + 1]->move(getNewOrientation(), _position, _size);

				if (bulletManager.getBulletMap()[i + 1]->getIsShooting() == false)
				{
					isShootingVector[i] = false;
				}

			}

		}
	}
	

}

void Enemy::move() //temporaire
{
	switch (personalNumberCharacter)
	{
	case 2:
	{
			  _position.x = 100 * cos(moveVar) + 350;
			  _position.y = 100 * sin(moveVar) +250;
			  break;
	}
	case 3:
	{
			  _position.x =250 * cos(moveVar) + 350;
			  _position.y = 250 * sin(moveVar) + 260;
			  break;

	}
	case 4:
	{
			  _position.x = 250 * cos(moveVar+1) + 350;
			  _position.y = 250 * sin(moveVar+1) + 260;
			  break;
			  

	}
	case 5:
	{
			  _position.x = 250 * cos(moveVar + 2) + 350;
			  _position.y = 250 * sin(moveVar + 2) + 260;
			  break;

	}


	}
	
	
		
	(moveVar=float(moveVar+speed.x/10));
}


void Enemy::setShoot(int i, bool x)
{
	isShootingVector[i] = x;
}



void Enemy::activateShoot(int i)
{
	
	for (int it = 1; it !=i; it++)
	{	
		
		if (itShootVector == numberBullet)
		{
			itShootVector = 0;
		}
		setShoot(itShootVector, 1);
		itShootVector++;
	}
	
}

Vector2f Enemy::getNewOrientation()  //temporaire
{
	if (compteurOrientation == 10)
	{
		compteurOrientation = 0;
	}
	

	orientation = Vector2f(cos(compteurOrientation), sin(compteurOrientation));
	compteurOrientation++;
	return orientation;
}

void Enemy::stopAction()
{
	for (auto it : getBulletManager().getBulletMap())
	{
		it.second->setIsShooting(false);
	}

}

void Enemy::characterInterpretEvent(EventEnum keyEnum)
{
	if (milliSecondCount == 500)
	{
		activateShoot(10);
		milliSecondCount = 0;
		
	}

	if (keyEnum==MILLISECOND_EVENT)
	{
		
		milliSecondCount++;
		
	}
	else
	{
		return;
	}
}